 
<%@page import="study.itwill.team5.board.BoardCategoryItem"%>
<%@page import="study.itwill.team5.board.BoardCategory"%>
<%@page import="study.itwill.team5.member.MemberItem"%>
<%@page import="study.itwill.team5.member.Member"%>
<%@page import="java.util.ArrayList"%> 
<%@page import="study.itwill.common.DBHandler"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page trimDirectiveWhitespaces="true" %>
<%@ include file="../dbcon.jsp"%>
<%
    String category = request.getParameter("category");

	// 회원목록에 대한 ArrayList 받아오기
	Member mem = new Member();
	ArrayList<MemberItem> mem_list = mem.listMember(0); 
	
	BoardCategory bc = new BoardCategory();
	ArrayList<BoardCategoryItem> bc_list = bc.listBoardCategory();
%>
<!DOCTYPE html>
<html lang="ko">
  <head>
  <%@ include file="../head.jsp"%>
	
  </head>
  <body>
  	<%@ include file="../menu.jsp"%>
  	<%DBHandler.disconnect();%>
	<div class="container">
		<div class="page-header">
		<h1>신규 게시물 추가 - <small>새로운 게시물을 추가하세요.</small></h1>
	</div>
		
		<form id="frmBoardAdd" class="form-horizontal" role="form" method="post" action="addBoardOk.jsp">
			<fieldset>
				 <div class="form-group">
					<label for="board_category_seq" class="col-md-2 control-label">게시판 카테고리</label>
					<div class="col-md-10">
						<select id="board_category_seq" name="board_category_seq" class="form-control">
							<option>----- 선택하세요 -----</option>
							<%
								if (bc_list != null) {
									for (int i = 0; i < bc_list.size(); i++) {
										BoardCategoryItem item = bc_list.get(i);
							%>
							<option value="<%=item.getSeq()%>"><%=item.getCategory_name()%></option>
							<%
									}
								}
							%>
							 
						</select>
					</div>
				</div>
				
				<div class="form-group">
					<label for="member_seq" class="col-md-2 control-label">회원이름</label>
					<div class="col-md-10">
						<select id="member_seq" name="member_seq" class="form-control">
							<option>----- 선택하세요 -----</option>
						<%
								if (mem_list != null) {
									for (int i = 0; i < mem_list.size(); i++) {
										MemberItem item = mem_list.get(i);
							%>
							<option value="<%=item.getSeq()%>"><%=item.getUser_name()%></option>
							<%
								}
								}
							%>
						</select>
					</div>
				</div>
							
				<!-- 입력양식 -->
				<div class="form-group">
					<label for="title" class="col-md-2 control-label">제목</label>
					<div class="col-md-10">
						<input type="text" class="form-control" id="title" placeholder="제목을 입력하세요" name="title">
					</div>
				</div>
				
				<div class="form-group">
					<label for="content" class="col-md-2 control-label">내용</label>
					<div class="col-md-10">
						<textarea class="form-control" id="content" rows="7" placeholder="내용을 입력하세요" name="content"></textarea>
					</div>
				</div>
				  
						
				
				<div class="form-group">
					<div class="col-md-offset-2 col-md-10">
						<div class="row">
							<div class="col-md-6">
								<button type="submit" class="btn btn-primary btn-block">저장하기</button>
							</div>
							<div class="col-md-6">
								<button type="reset" class="btn btn-warning btn-block">다시작성</button>
							</div>
						</div>
						
					</div>
				</div>
			</fieldset>
		</form>
	</div>

	<!-- Javascript -->
	<script src="/italia/assets/js/jquery.js"></script>
	<script src="/italia/assets/js/bootstrap.min.js"></script>
	<!-- 형식검사 클래스 참조 -->
	<script src="/italia/assets/js/string.js"></script>
	<!-- 구현부분 -->
	<script type="text/javascript">
		// jquery main()
		$(function() {
			// id속성이 frmStudentAdd인 대상에 대한 전송 이벤트
			$("#frmBoardAdd").submit(function() {
				/**
				*	string.js 사용 방법
				* -------------------------
				*		var str = "가나다";
				*		if (!str.isEmail()) {
				*			... 이메일 형식이 아님 ...	
				*		}
				*/
				 
				if ($("select[name='board_category_seq'] > option:selected").index() < 1) {
					alert("카테고리를 선택하세요.");
					$("select[name='board_category_seq']").focus();
					return false;
				}
				
				if ($("select[name='member_seq'] > option:selected").index() < 1) {
					alert("회원을 선택해 주세요.");
					$("select[name='member_seq']").focus();
					return false;
				}
				 
				var name = $("input[name='title']").val(); 
				if (!name.isValue()) {
					alert("제목을 입력하세요.");
					$("input[name='title']").focus();
					return false;
				}
				 
				if (!$("input[name='content']").val().isValue()) {
					alert("내용을 입력하세요.");
					$("input[name='content']").focus();
					return false;
				}
				  
				
			});
		});
	</script>
		
  </body>
</html>